﻿using System.Windows.Forms;

namespace Landpy.CruiseControlNet.ConfigurationSidekick.ConfigTreeModule
{
    class CruiseControlHandler : UpdateChildrenNode
    {
        public override void UpdateChildrenNodes(ChildrenNodeContext childrenNodeContext)
        {
            var treeNodeIndentity = this.GetTreeNodeIndentity(childrenNodeContext);
            if (treeNodeIndentity.Type == TreeNodeType.CruiseControl)
            {
                TreeView treeView = childrenNodeContext.SelectedNode.TreeView;
                childrenNodeContext.SelectedNode.Remove();
                var treeNodesBuilder = this.GetTreeNodesBuilder(childrenNodeContext.CruiseControl);
                var cruiseControlNode = treeNodesBuilder.BuildCruiseControlNode();
                treeNodesBuilder.BuildInternalSecurityNode(cruiseControlNode);
                treeNodesBuilder.BuildProjectsNode(cruiseControlNode);
                treeView.Nodes.Add(treeNodesBuilder.CruiseControlTreeNode);
                treeNodesBuilder.CruiseControlTreeNode.Expand();
            }
            else
            {
                this.Successor.UpdateChildrenNodes(childrenNodeContext);
            }
        }
    }
}
